﻿using AnesSystem.ViewModels;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AnesSystem.Controls
{
    public class BasePacuRecordCtrl : BaseTableControl
    {
        #region Variables


        #endregion


        #region Constructor
        public BasePacuRecordCtrl()
        {
            this.Loaded += BasePacuRecordCtrl_Loaded;
        }


        #endregion


        #region Properties


        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods


        #endregion


        #region Public/ProtectedMethods
        /// <summary>
        /// 复苏单打印
        /// </summary>
        public override void PrintVisual()
        {
            
            List<BaseTableControl> list = UIHelper.FindVisualChild<BaseTableControl>(Content as FrameworkElement);
            List<FrameworkElement> temp = new List<FrameworkElement>();
            foreach (var item in list)
            {
                temp.Add(item);
            }
            Print(temp);
        }
        public override void InvokePrePrint()
        {
            CancelButton();
        }

        public override void InvokeOverPrint()
        {
            AddButton();
        }

        private void AddButton()
        {
            if (DataManager.Instance.CurrentControl is BaseAnesRecordCtrl)
            {
                for (int i = 1; i <= DataManager.Instance.CurrentPatientLink.Status.TotalPage; i++)
                {
                    (DataManager.Instance.AnesRecordCtrl.ViewModel as AnesRecordCtrlViewModel).AnesRecordCtrlViewModels[i].AnesEventAndMedicineCtrlViewModel.IsPrint = Visibility.Visible;
                    (DataManager.Instance.AnesRecordCtrl.ViewModel as AnesRecordCtrlViewModel).AnesRecordCtrlViewModels[i].RealTimeItemCtrlViewModel.IsPrint = Visibility.Visible;
                }

            }
            if (DataManager.Instance.CurrentControl is BasePacuRecordCtrl)
            {
                for (int i = 1; i <= DataManager.Instance.CurrentPatientLink.Status.PacuPage; i++)
                {
                    (DataManager.Instance.PacuRecordCtrl.ViewModel as PacuRecordCtrlViewModel).PacuRecordCtrlViewModels[i].PacuEventAndMedicineCtrlViewModel.IsPrint = Visibility.Visible;
                    (DataManager.Instance.PacuRecordCtrl.ViewModel as PacuRecordCtrlViewModel).PacuRecordCtrlViewModels[i].PacuRealTimeItemCtrlViewModel.IsPrint = Visibility.Visible;
                }
            }
        }

        private void CancelButton()
        {
            if (DataManager.Instance.CurrentControl is BaseAnesRecordCtrl)
            {
                for (int i = 1; i <= DataManager.Instance.CurrentPatientLink.Status.TotalPage; i++)
                {
                    (DataManager.Instance.AnesRecordCtrl.ViewModel as AnesRecordCtrlViewModel).AnesRecordCtrlViewModels[i].AnesEventAndMedicineCtrlViewModel.IsPrint = Visibility.Hidden;
                    (DataManager.Instance.AnesRecordCtrl.ViewModel as AnesRecordCtrlViewModel).AnesRecordCtrlViewModels[i].RealTimeItemCtrlViewModel.IsPrint = Visibility.Hidden;
                }

            }
            if (DataManager.Instance.CurrentControl is BasePacuRecordCtrl)
            {
                for (int i = 1; i <= DataManager.Instance.CurrentPatientLink.Status.PacuPage; i++)
                {
                    (DataManager.Instance.PacuRecordCtrl.ViewModel as PacuRecordCtrlViewModel).PacuRecordCtrlViewModels[i].PacuEventAndMedicineCtrlViewModel.IsPrint = Visibility.Hidden;
                    (DataManager.Instance.PacuRecordCtrl.ViewModel as PacuRecordCtrlViewModel).PacuRecordCtrlViewModels[i].PacuRealTimeItemCtrlViewModel.IsPrint = Visibility.Hidden;
                }
            }

        }

        /// <summary>
        /// 复苏单刷新
        /// </summary>
        public override void Refesh()
        {
            MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Visible;
            PacuProcessViewModel.Instance.Refresh();
            MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Collapsed;
        }
        /// <summary>
        /// 复苏单加载
        /// </summary>
        public virtual void PacuLoaded()
        {
            DataManager.Instance.TableHeaderCtrl.ViewModel.DefaultDisplayModel = 1;
            DataManager.Instance.IsInAorP = Constants.ISPACU;
            PacuProcessViewModel.Instance.LoadData();
        }
        #endregion


        #region EventHandlers
        private void BasePacuRecordCtrl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            PacuLoaded();
        }

        #endregion
    }
}
